package com.sergiandreplace.kaboom.util;

import android.graphics.Bitmap;

public class GraphicsUtil
{

	public static Bitmap getResizedBitmap(Bitmap bm, int newSize)
	{

		int width = bm.getWidth();
		int height = bm.getHeight();
		int scaleDimension = getScale(bm, newSize);
		float scale = ((float) newSize) / scaleDimension;

		// create a matrix for the manipulation
//		Matrix matrix = new Matrix();
		// resize the bit map
//		matrix.postScale(scale, scale);
		Bitmap resizedBitmap = Bitmap.createScaledBitmap(bm, (int)(width*scale), (int)(height*scale), false);
		bm.recycle();
		return resizedBitmap;

	}

	public static int getScale(Bitmap bm, int newSize)
	{
		int width = bm.getWidth();
		int height = bm.getHeight();
		int scaleDimension = (width > height) ? width : height;
		return scaleDimension;
	}

	public static int getScaledWidth(Bitmap bm, int newSize)
	{
		return bm.getWidth() * getScale(bm, newSize);
	}

	public static int getScaledHeight(Bitmap bm, int newSize)
	{
		return bm.getHeight() * getScale(bm, newSize);
	}
}
